package com.itheima.controller;

import com.itheima.pojo.SmsFlashPromotionProductRelation;
import com.itheima.service.SmsFlashPromotionProductRelationService;
import com.itheima.vo.PageResultVo;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("flashProductRelation")
public class SmsFlashPromotionProductRelationController {
    @Autowired
    private SmsFlashPromotionProductRelationService smsFlashPromotionProductRelationService;

    /**
     * 批量选择商品添加关联
     * @param relationList
     * @return
     */
    @PostMapping("create")
    public Result create(@RequestBody List<SmsFlashPromotionProductRelation> relationList){
        smsFlashPromotionProductRelationService.create(relationList);
        return Result.success(null);
    }

    /**
     * 删除关联
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        smsFlashPromotionProductRelationService.deleteById(id);
        return Result.success(null);
    }

    /**
     *分页查询不同场次关联及商品信息
     * @param flashPromotionId
     * @param flashPromotionSessionId 编号
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("list")
    public Result list(Integer flashPromotionId,Integer flashPromotionSessionId,
                       @RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize){
        PageResultVo resultVo=smsFlashPromotionProductRelationService.list(flashPromotionId,flashPromotionSessionId,pageNum,pageSize);
        return Result.success(resultVo);
    }

    /**
     * 修改关联信息
     * @param id
     * @param relation
     * @return
     */
    @PostMapping("update/{id}")
    public Result updateById(@PathVariable("id") Integer id,@RequestBody SmsFlashPromotionProductRelation relation){
        smsFlashPromotionProductRelationService.updateById(id,relation);
        return Result.success(null);
    }

    /**
     * 获取管理商品促销信息
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Result getRelation(@PathVariable("id") Integer id){
        SmsFlashPromotionProductRelation smsFlashPromotionProductRelation = smsFlashPromotionProductRelationService.getRelation(id);
        return Result.success(smsFlashPromotionProductRelation);
    }

}
